﻿#ifndef __THREAD_H__
#define __THREAD_H__

#include "Common.h"

namespace sky
{
    // 线程
    // 线程任务类前置声明
    class ThreadRunnable;

    #define WAIT_TERMINATE_TIME 3000

    // 线程封装
    class SKY_EXPORT Thread
    {
    protected:
        unsigned long mThreadId;
        void * mThreadHandle;

    public:
        Thread();
        ~Thread();
    
		//可执行的任务，外面要是释放了，一定要先调用线程停止
		ThreadRunnable* m_pTask;

    public:
        bool spawn(ThreadRunnable * task, int priority = 0);
        void clearTask();
        void wait();
        void start();
        void pause();
        void terminate();

        static void sleep(unsigned long timeout);

        // 通知线程停止
        void notifyStop();

        // 查询线程是否已经停止
        bool isClose();
    
    protected:
        static unsigned int __stdcall _dispatch(void * arg);
    };

} // namespace sky



#endif